#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define NUMBER	500000
#define FORZ(i, max)	for(i = 0; i < max; i++)
#define SUM(n) ((n)*((n)+1ll)/2ll)

typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	ull n=2ll,j=2ll,k,m;
	int i=1,M;
	unsigned short *am;
	
	//for(i=0;i<=M;i++)printf("[%d]%d\n",i,am[i]);
	//printf("\n");
	scanf("%llu",&n);
	
	if(n<1000000000000ll) M=6137+1;
	else M=11000000+1;

	am=malloc(sizeof(unsigned short)*M);
	am[1]=1;am[2]=am[3]=2;
	for(m=4ll,i=3ll;i<(M);i++) {
		for(j=m;j<m+am[i]&&j<=M;j++)am[j]=i;
		m=j;
	}

	ull s1=1,s2=1;m=1ll;k=1ll;
	for(i=2;i<M&&k<n;i++) {
		s1=s2;
		s2=s1+am[i];
		k+=(ull)i*(ull)(s2-s1);
		m+=(ull)(s2-s1);
	}
	
	i--;
	k-=i*(s2-s1);
	m-=(s2-s1);
	
	for(j=0ll;j<s2-s1&&k<n;j++) {
		k+=i;
		m++;
	}
	
	printf("%llu\n",m);
	
	return 0;
}
